package com.isunland.managesystem.utils;

import android.view.View;
import android.widget.TextView;
import com.isunland.managesystem.R;
import java.util.HashMap;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/5/26 14:11
 */

public class MyViewUtil {
  private static final int PARAMS_KEY = R.id.params_key;

  /**
   * 启用或禁用所有view
   */
  public static void setEnableAll(boolean enable, View... views) {
    if (views == null) return;
    for (View v : views) {
      if (v != null) {
        v.setEnabled(enable);
      }
    }
  }

  public static void setVisibilityAll(int kind, View... views) {
    if (views == null) return;
    for (View v : views) {
      if (v != null) {
        v.setVisibility(kind);
      }
    }
  }

  /**
   * 是否为空
   */
  public static boolean isEmptyText(TextView... views) {
    if (views == null) return true;
    for (TextView v : views) {
      if (MyStringUtil.isEmptyTextView(v)) return true;
    }
    return false;
  }

  public static void setParams(TextView view, String key) {
    if (view == null) return;
    if (key == null) key = "";
    view.setTag(PARAMS_KEY, key);
  }

  public static HashMap<String, String> getParams(TextView... views) {
    ParamsNotEmpty params = new ParamsNotEmpty();
    if (views == null) return params.getParams();
    for (TextView v : views) {
      if (v != null) {
        params.put(v.getTag(PARAMS_KEY) instanceof String ? (String) v.getTag(PARAMS_KEY) : "",
            MyStringUtil.getText(v));
      }
    }
    return params.getParams();
  }
}
